package com.globallogic.vacationplanner.web.helper;

import org.apache.log4j.Logger;

import com.globallogic.vacationplanner.transfer.dto.impl.ProjectDto;
import com.globallogic.vacationplanner.web.controller.ProjectBean;
import com.globallogic.vacationplanner.web.controller.UserBean;
import com.globallogic.vacationplanner.web.exceptions.ViewException;

public class ProjectBeanHelper {
	private static Logger LOGGER = Logger.getLogger(ProjectBeanHelper.class);

	public static ProjectDto buildProjectDto(ProjectBean projectBean) throws ViewException {
		LOGGER.info("start build projectDto from project backing bean");
		ProjectDto projectDto = null;
		if (projectBean.getName().isEmpty()
				|| projectBean.getDescription().isEmpty()) {
			LOGGER.info("Project description or project name is empty");
			throw new ViewException();
		} else {
			projectDto = new ProjectDto();
			UserBean userBean = projectBean.getUserBean();
			projectDto.setLoginCreator(userBean.getLogin());
			projectDto.setName(projectBean.getName());
			projectDto.setDescription(projectBean.getDescription());
			projectDto.setState("Open");
			projectDto.setUserMembersList(projectBean.getSelectedUsers());
			LOGGER.info("build projectDto was success");
		}
		return projectDto;
	}
}
